package net.begincode.service.manager.impl;

import java.util.List;

import utils.CacheUtils;
import config.DbTemplate;
import net.begincode.bean.BcDown;
import net.begincode.bean.BcNavigation;
import net.begincode.service.course.impl.CourseServiceImpl;
import net.begincode.service.manager.ManagerService;

public class ManagerServiceImpl implements ManagerService {
	private ManagerServiceImpl() {
	}

	private static ManagerServiceImpl instance = null;

	public static ManagerServiceImpl getInstance() {
		if (instance == null) {
			synchronized (ManagerServiceImpl.class) {
				if (instance == null) {
					instance = new ManagerServiceImpl();
				}
			}
		}
		return instance;
	}
	@Override
	public List<BcNavigation> selNavByPid(int pid) {
		// TODO Auto-generated method stub
		String selSql = " select * from bc_navigation where up_nav_id = ? and sts = '1' ";
		return DbTemplate.queryForList(selSql, new Object[]{pid}, BcNavigation.class);
	}
	@Override
	public BcNavigation selNavById(String id) {
		// TODO Auto-generated method stub
		String selSql = " select * from bc_navigation where bc_navigation_id = ? and sts = '1' ";
		return DbTemplate.queryForObject(selSql, new Object[]{id}, BcNavigation.class);
	}
	@Override
	public BcNavigation selNavByIdCache(String id) {
		// TODO Auto-generated method stub
		String selSql = " select * from bc_navigation where bc_navigation_id = ? and sts = '1' ";
		Object dbEle = CacheUtils.getEleByNameAndKey(CacheUtils.HOME_PAGE_CACHE, "nav"+id);
		if(dbEle != null){
			return (BcNavigation)dbEle;
		}else{
			BcNavigation ccs = DbTemplate.queryForObject(selSql, new Object[]{id}, BcNavigation.class);
			CacheUtils.addEleByParam(CacheUtils.HOME_PAGE_CACHE, "nav"+id, ccs);
			return ccs;
		}
	}

}
